home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue64 / Alfresco / TstSort.dpr < prev   
Encoding:
Text File  |  2000-10-23  |  1.2 KB  |  64 lines

  1. program TstSort;
  2.  
  3. {$apptype console}
  4.  
  5. uses
  6.   Windows,
  7.   AASorter in 'AASorter.pas';
  8.  
  9. procedure InitRandom(var MyRec : shortstring);
  10. var
  11.   i : integer;
  12. begin
  13.   MyRec[0] := #15;
  14.   for i := 1 to 15 do
  15.     MyRec[i] := char(Random(26) + ord('A'));
  16. end;
  17.  
  18. function MyCompare(const aItem1, aItem2 : pointer) : integer;
  19. var
  20.   Item1 : ^ShortString;
  21.   Item2 : ^ShortString;
  22. begin
  23.   Item1 := aItem1;
  24.   Item2 := aItem2;
  25.   if (Item1^ < Item2^) then
  26.     Result := -1
  27.   else if (Item1^ = Item2^) then
  28.     Result := 0
  29.   else
  30.     Result := 1;
  31. end;
  32.  
  33. var
  34.   Sorter : TaaSorter;
  35.   PrevRec, MyRec  : string[15];
  36.   i      : integer;
  37. begin
  38.   writeln('Starting test');
  39.   Sorter := TaaSorter.Create;
  40.   try
  41.     Sorter.MaxRecordCount := 1000;
  42.     Sorter.RecordLength := 16;
  43.     Sorter.Compare := MyCompare;
  44.     for i := 1 to 10000 do begin
  45.       InitRandom(MyRec);
  46.       Sorter.Add(MyRec);
  47.     end;
  48.  
  49.     PrevRec := '';
  50.     while Sorter.Get(MyRec) do begin
  51. //      writeln(MyRec);
  52.       if (MyRec < Prevrec) then begin
  53.         writeln('Error: out of sequence');
  54.         readln;
  55.       end;
  56.       PrevRec := MyRec;
  57.     end;
  58.   finally
  59.     Sorter.Free;
  60.   end;
  61.   writeln('Completed test');
  62.   readln;
  63. end.
  64.